<%@ codepage=65001%>
<!-- #include file="conn.asp" -->
<!--#include file="wangDian_UpLoad_Class.asp"-->
<%
Session.CodePage=65001
Response.Charset="utf-8"


'wangdianName             '网点名称
'wangdianAddress          '网点地址
'province                 '省
'city                     '市
'district                 '区
'saleAreaId               '所属销售片区Id 从片区表里获得
'wangdianOwen             '所属销售片区
'wangdianfuzeren          '网点负责人姓名
'wdfzrTel                 '网点负责人联系电话
'salerId                  '销售人员ID   从销售人员表里获得
'wangdianPhoto            '网点照片
'wangdianOwen             '网点是属于那个客户的

sType = request("sType")
if (IsEmpty(request("id")) or request("id")="" ) then
	id=0
else
	id=cint(trim(request("id")))
end if
wangdianName = request("wangdianName")
wangdianAddress = request("wangdianAddress")
wangdianAddressLng = request("wangdianAddressLng")
wangdianAddressLat = request("wangdianAddressLat")
province = request("province")
city = request("city")
district = request("district")
saleAreaId = request("saleAreaId")
wangdianAreaOwen = request("wangdianAreaOwen")
wangdianfuzeren = request("wangdianfuzeren")
wdfzrTel = request("wdfzrTel")
wangdianyewuren = request("wangdianyewuren")
wdywrTel = request("wdywrTel")
saleId = request("saleId")
wangdianPhoto = request("wangdianPhoto")
wangdianOwen = request("wangdianOwen")
beizhu = request("beizhu")

saleAreaId=1
saleId=1
if sType = "add" then
	on error resume next
	if id>0 then    'update
		sql="update wangdian set wangdianName='"&wangdianName&"',wangdianAddress='"&wangdianAddress&"',wangdianAddressLng='"& wangdianAddressLng &"',wangdianAddressLat='"& wangdianAddressLat &"',province='"&province&"',city='"&city&"',district='"&district&"',saleAreaId="&saleAreaId&",wangdianAreaOwen='"&wangdianAreaOwen&"',wangdianfuzeren='"&wangdianfuzeren&"',wdfzrTel='"&wdfzrTel&"',wangdianyewuren='"&wangdianyewuren&"',wdywrTel='"&wdywrTel&"',saleId="&saleId&",wangdianPhoto='"&wangdianPhoto&"',wangdianOwen='"&wangdianOwen&"',beizhu='"&beizhu&"' where id="&id
		conn.execute(sql)
		if err.number=0 then
			response.write "{success:true,msg:3}"
		else
			response.write "{success:false,msg:4}"
		end if
	else
		
		'------------------------上传网点照片开始--------------------------
		dim upload
		set upload = new AnUpLoad
		upload.Exe = "jpg|bmp|jpeg|gif|png"
		upload.MaxSize = 4 * 1024 * 1024 '2M
		upload.GetData()
		if upload.ErrorID>0 then 
			response.Write upload.Description
		else
			dim savpath,sFileName,strResult
			for each f in upload.files(-1)
				dim file
				set file = upload.files(f)
				sFileName = file.filename
				savepath = "wangDianUpfile/"&sFileName
				'if not(file is nothing) then
		'			result = file.saveToFile(savepath,0,true)
		'			if result then
		'				strResult = 0
		'			else
		'				strResult = 1
		'				exit for
		'			end if
		'		end if
				set file = nothing
				'response.Write "999999999999999999999="&savepath&"===="
			next
			'response.Write "{success:true,message:"&strResult&"}"
			
		end if
		set upload = nothing
		'------------------------上传网点照片开始--------------------------
	
		sql="insert into wangdian ([wangdianName],[wangdianAddress],[wangdianAddressLng],[wangdianAddressLat],[province],[city],[district],[saleAreaId],[wangdianAreaOwen],[wangdianfuzeren],[wdfzrTel],[wangdianyewuren],[wdywrTel],[saleId],[wangdianPhoto],[wangdianOwen],[beizhu]) values ('"&wangdianName&"','"&wangdianAddress&"','"&wangdianAddressLng&"','"&wangdianAddressLat&"','"&province&"','"&city&"','"&district&"',"&saleAreaId&",'"&wangdianAreaOwen&"','"&wangdianfuzeren&"','"&wdfzrTel&"','"&wangdianyewuren&"','"&wdywrTel&"',"&saleId&",'"&savepath&"','"&wangdianOwen&"','"&beizhu&"')"
		
		'sql="insert into wangdian ([wangdianName],[wangdianAddress],[wangdianAddressLng],[wangdianAddressLat],[province],[city],[district],[saleAreaId],[wangdianAreaOwen],[wangdianfuzeren],[wdfzrTel],[wangdianyewuren],[wdywrTel],[saleId],[wangdianPhoto],[wangdianOwen],[beizhu]) values ('"&wangdianName&"','"&wangdianAddress&"','"&wangdianAddressLng&"','"&wangdianAddressLat&"','"&province&"','"&city&"','"&district&"',"&saleAreaId&",'"&wangdianAreaOwen&"','"&wangdianfuzeren&"','"&wdfzrTel&"','"&wangdianyewuren&"','"&wdywrTel&"',"&saleId&",'"&wangdianPhoto&"','"&wangdianOwen&"','"&beizhu&"')"
		conn.execute(sql)
		if err.number=0 then
			response.write "{success:true,msg:0}"
		else
			response.write "{success:false,msg:1}"
		end if
	end if
elseif sType = "del" then
	arrvalue=split(id,",")
    for i=0 to ubound(arrvalue)
      	on error resume next
	  	sql="delete from wangdian where id=" & arrvalue(i)
		conn.execute(sql)
    next
elseif sType = "update" then
else
end if

conn.close

%>